#include<bits/stdc++.h>

using namespace std;
int t,n,m;
const int N=2e6+10;
vector<int>a[N];
int main(){
	cin>>t;
	bool _=false;
	for(int o=1;o<=t;o++){
			if(_) puts("");
				_=true;
		cin>>n>>m;
		for(int i=1;i<=n;i++){
			int x;
			cin>>x;
			a[i].clear();
			for(int j=1;j<=x;j++){
				int d;
				cin>>d;
				a[i].push_back(d);
			}
		}
		printf("Case #%d: \n",o);
        for(int j=1;j<=m;j++){
			int l,s;
			cin>>l>>s;
			int res=l,f=0;
			//cout<<a[res][1]<<endl;
			for(int i=0;i<s;i++){
				int x;
				cin>>x;
				//cout<<res<<endl;
				if(a[res].size()<x||!x)f=1;
				if(f==1)continue;
				res=a[res][x-1];
				//	cout<<x-1<<endl;
			}
			if(!f)cout<<res<<endl;
			else cout<<"Packet Loss"<<endl;
		}
	}
}
